define(['dojo/_base/declare', 'dojo/Evented'], function(declare, Evented) {
	return declare('js/layer/Base', [Evented], {
		constructor: function(map, config) {
			//config
			this.layer = null;
			this.type = null;
			this.name = null;
			this.visible = true;
			this.id = null;
			this.url = null;
			
			this.map = map;
			this.initLayer(config);
		},
		initLayer: function(config) {
			//给layer对象赋值
			this.type = config.type;
			this.name = config.name;
			this.id = config.id? config.id: dojox.uuid.generateRandomUuid();
			config.id = this.id;
			this.url = config.url;
			
			this.layer = this.createLayer(config);
			
			if(config.viewonly) {
				this.layer.set('viewonly', true);
				this.viewonly = true;
			}
			
			this.initFeatures(config);
		},
		createLayer: function(config) {
			
		},
		getSource: function() {
			return this.layer.getSource();
		},
		setSource: function(source) {
			this.layer.setSource(source);
		},
		setVisible: function(visibility) {
			this.visible = visibility;
			this.layer.setVisible(visibility);
		},
		
		getFeatures: function() {
			var features = this.getSource().getFeatures();
			var  list = [];
			$.each(features, function(index, item) {
				var prop = item.getProperties();
				prop.fid = item.getId();
				list.push(prop);
			});
			return list;
		},
		getFeature: function(field, value) {
			var feature = null;
			this.getSource().forEachFeature(function(item) {
				if(item.getProperties()[field] == value) {
					feature = item;
					return false;
				}
			}, this);
			return feature;
		},
		clear: function() {
			this.getSource().clear();
		},
		addFeature: function(feature) {
			this.getSource().addFeature(feature);
		},
		//values：值数组
		hideFeature: function(field, values) {
			var source = this.getSource();
			var features = source.getFeatures();
			$.each(features, function(index, item) {
				for(var i = 0; i < values.length; i++) {
					var prop = item.getProperties();
					if(prop[field] == values[i]) {
						item.set('_hidden', true);
					}
				}
			});
			source.refresh();
		},
		//values：值数组
		showFeature: function(field, values) {
			var source = this.getSource();
			var features = source.getFeatures();
			$.each(features, function(index, item) {
				for(var i = 0; i < values.length; i++) {
					var prop = item.getProperties();
					if(prop[field] == values[i]) {
						item.set('_hidden', false);
					}
				}
			});
			source.refresh();
		},
		showAllFeatures: function() {
			var source = this.getSource();
			var features = source.getFeatures();
			$.each(features, function(index, item) {
				item.set('_hidden', false);
			});
			source.refresh();
		},
		hideAllFeatures: function() {
			var source = this.getSource();
			var features = source.getFeatures();
			$.each(features, function(index, item) {
				item.set('hidden', true);
			});
			source.refresh();
		}
	})
});